<template>
  <div class="comment-image">
    <!-- 图片列表 -->
    <div class="comment-pics">
      <div class="pic-item" :class="{ active: activeIndex === index }" v-for="(image, index) in images" :key="index" @click="showLargeCommentPictureHandler(index)">
        <img v-lazy="image" />
      </div>
    </div>
    <!-- 评价图片大图 -->
    <div class="comment-pic-large" :class="{ show: activeIndex >= 0 }">
      <div class="header"><span class="iconfont icon-cuowu" @click="resetCommentPicShowHandler()"></span></div>
      <img v-lazy="images[activeIndex]" v-if="images[activeIndex]" />
    </div>
  </div>
</template>

<script>
export default {
  props: {
    images: {
      type: Array,
      default: () => []
    }
  },

  data () {
    return {
      activeIndex: -1
    }
  },

  methods: {
    /**
     * 展示大图
     * @param { Number } index 图片索引值
     */
    showLargeCommentPictureHandler (index) {
      this.activeIndex = index
    },

    /**
     * 重置评价
     */
    resetCommentPicShowHandler () {
      this.activeIndex = -1
    }
  }
}
</script>

<style lang="less" scoped>
@import "../../styles/variable.less";

.comment-image {
  .comment-pics {
    margin-top: 10px;
    .pic-item {
      align-items: center;
      border: 1px solid @border-grey;
      cursor: pointer;
      display: flex;
      width: 140px;
      height: 140px;
      justify-content: center;
      margin-right: 10px;
      img {
        max-width: 100%;
        max-height: 100%;
      }
      &.active {
        border: 1px solid @font-color-golden;
      }
    }
  }
  .comment-pic-large {
    background-color: #f5f5f5;
    border-top: 1px solid #e8e8e8;
    display: none;
    padding: 0px 10px 50px;
    margin: 10px 0px;
    overflow: hidden;
    .header {
      padding: 0px 10px;
      height: 50px;
      line-height: 50px;
      text-align: right;
      .iconfont {
        cursor: pointer;
        font-size: 24px;
      }
    }
    img {
      width: 100%;
    }
    &.show {
      display: block;
    }
  }
}
</style>
